#include "FileSaver.h"
#include "jsonutils/JsonUtil.h"
#include <QDir>
#include <QDebug>
#include <QDataStream>
#include <QFile>
#include <QSet>


FileSaver::FileSaver(QObject *parent) : QObject(parent)
{
    // make sure the path is existed
    QDir dir("./");
    if (!dir.exists("jsons"))
    {
        dir.mkpath("jsons");
    }
}

void FileSaver::write(QVariant content)
{
    //    QFile file(path.toString());
    //    if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
    //    {
    //        emit sigError(QVariant(QString("file open failed when write.")));
    //        return;
    //    }
    //    QDataStream ds(&file);
    //    ds << content;


    qDebug() << "content: " << content;

    QString strPath = "jsons/feed.info";
    JsonUtil::saveJson(content.toList(), strPath);
}

QVariant FileSaver::getFeedInfo()
{
    QVariantList contentTmp;
    JsonUtil::loadJson("jsons/feed.info", contentTmp);

    return QVariant(contentTmp);
}




